{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9c1f76b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入支付宝余额：100\n",
      "-----商品列表-----\n",
      "商品编号：0，名称：牛肉，价格：50 元\n",
      "商品编号：1，名称：猪肉，价格：40 元\n",
      "商品编号：2，名称：羊肉，价格：50 元\n",
      "商品编号：3，名称：鸡肉，价格：20 元\n",
      "商品编号：4，名称：鱼肉，价格：15 元\n",
      "请输入商品编号:0\n",
      "-----商品列表-----\n",
      "商品编号：0，名称：牛肉，价格：50 元\n",
      "商品编号：1，名称：猪肉，价格：40 元\n",
      "商品编号：2，名称：羊肉，价格：50 元\n",
      "商品编号：3，名称：鸡肉，价格：20 元\n",
      "商品编号：4，名称：鱼肉，价格：15 元\n",
      "请输入商品编号:退出\n",
      "余额：50,购物车：[['牛肉', 50]]\n"
     ]
    }
   ],
   "source": [
    "goods_list = [\n",
    "[\"牛肉\",50],\n",
    "[\"猪肉\",40],\n",
    "[\"羊肉\",50],\n",
    "[\"鸡肉\",20],\n",
    "[\"鱼肉\",15]    \n",
    "]\n",
    "\n",
    "good_list = []\n",
    "\n",
    "Balance = int(input(\"请输入支付宝余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"-----商品列表-----\")\n",
    "    for i in range(len(goods_list)):\n",
    "             print(\"商品编号：%s，名称：%s，价格：%d 元\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "\n",
    "    choice = input(\"请输入商品编号:\")\n",
    "    if choice.isdigit():\n",
    "        if int(choice) < len(goods_list):\n",
    "            if Balance > goods_list[int(choice)][1]:\n",
    "                Balance = Balance - goods_list[int(choice)][1]\n",
    "                good_list.append(goods_list[int(choice)])\n",
    "                pass\n",
    "            else:\n",
    "                print(\"您的余额不足\")\n",
    "            pass\n",
    "        \n",
    "    elif choice == \"退出\":\n",
    "     print(\"余额：%s,购物车：%s\" % (Balance,good_list ))\n",
    "     break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4283b4f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe345628",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
